/**
 * Copyright SunEEE Limited (c) 2014. All rights reserved.
 * This software is proprietary to and embodies the confidential
 * technology of SunEEE Limited.  Possession, use, or copying
 * of this software and media is authorized only pursuant to a
 * valid written license from SunEEE or an authorized sublicensor.
 */
package com.base.core.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

/**
 * ZhiLi:      Set the Spring context
 * @version   Revision History
 * <pre>
 * Author     Version       Date        Changes
 * ZhiLi      1.0           2014年12月16日     Created
 *
 * </pre>
 * @since B2B1.0.0
 */
@Service
@Scope("singleton")
public class SpringContextHelper implements ApplicationContextAware {

    private static Logger logger = LoggerFactory.getLogger(SpringContextHelper.class);
    
    private static ApplicationContext context = null;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        logger.info("创建Spring context Helper");
        SpringContextHelper.context = applicationContext;
    }
    
    public static ApplicationContext getContext(){
        return context;
    }

    public static Object getBean(String name) {
        return context.getBean(name);
    }

    public static <T> T getBean(Class<T> clazz) {
        return context.getBean(clazz);
    }

}
